<script lang="ts" setup name="XtxCheckbox">
defineProps<{
  modelValue: boolean
}>()
const emit = defineEmits<{
  (e: 'update:modelValue', val: boolean): void
}>()
</script>

<template>
  <div @click="emit('update:modelValue', !modelValue)" class="xtx-checkbox">
    <transition name="checkbox">
      <i class="iconfont icon-checked" v-if="modelValue"></i>
      <i class="iconfont icon-unchecked" v-else></i>
    </transition>
    <span><slot></slot></span>
  </div>
</template>

<style scoped lang="less">
.xtx-checkbox {
  cursor: pointer;
  width: 16px;
  height: 16px;
  position: relative;
  top: -2px;
  display: inline-block;
  margin-right: 2px;
  .icon-checked {
    color: @xtxColor;
    ~ span {
      color: @xtxColor;
    }
  }
  i {
    position: absolute;
    top: 1px;
  }
  span {
    margin-left: 2px;
  }
}

// .v-enter-from
// .v-enter-active
// .v-enter-to
.checkbox-enter-from {
  opacity: 0;
  transform: scale(0.8);
}
.checkbox-enter-active {
  position: absolute;
  transition: all .3s;
}
.checkbox-enter-to {
  opacity: 1;
  transform: scale(1);
}

.checkbox-leave-from {
  opacity: 1;
  transform: scale(1);
}
.checkbox-leave-active {
  position: absolute;
  transition: all .3s;
}
.checkbox-leave-to {
  opacity: 0;
  transform: scale(0.8);
}


</style>